﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Caching;

/// <summary>
/// The purpose of this page is to show the user a friendlier
/// error page when an unexpected or unhandled exception 
/// occurs anywhere on the website.
/// </summary>
public partial class App_Common_Exception : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                string exceptionId = "ApplicationException_" + Request.Cookies["ApplicationException"]["ID"];
                System.Exception exception = (System.Exception)CacheFactory.GetCacheManager().GetData(exceptionId);

                if (exception != null)
                {
                    AppendExceptionMessage(exception);
                }
            }
            catch
            {
            }
        }
    }

    private void AppendExceptionMessage(System.Exception exception)
    {
        if (exception != null)
        {
            txtErrorDetails.Text += exception.Message + System.Environment.NewLine;
            AppendExceptionMessage(exception.InnerException);
        }
    }
}
